package com.playball.lottery.frm.yhzx;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.customview.BallDTO;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.frm.buyhall.SsqxhActivity;
import com.playball.lottery.frm.buyhall.SsqxhlbActivity;
import com.playball.lottery.frm.help.CaiPiaoHelp;
import com.playball.lottery.frm.kjinfo.KjinfoListByType;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.Constants;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.PreferencesUtils;


/**
 * 账号详情
 *
 * @author Administrator
 *
 */
public class AccountDetailActivity extends BaseActivity {

	private View loadMoreView;
	private Button loadMoreButton,btn_all,btn_buyLottery,btn_recharge,btn_reward,btn_drawings;
	// result返回集
	private List<Map<String, Object>> rData;
	// page返回集
	private Map<String, Object> pData;
	// 查询时间范围
	private int timeRegion;
	// 页号
	private int pageNo = 1;
	// 每页条数
	private int pageSize = 10;
	// 查询类型
	private int type = 0;
	// 是否有下一页
	private boolean nextPage;
	/** 记录总条数 */
	private int intTotalNum;
	private TextView selDate;
	private TextView selType;

	private ShowTipDialog showdialog = new ShowTipDialog();

	private Handler handler = new Handler();

	private PaginationAdapter adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());

	private boolean change = false;

	boolean isFirstLanch = true;

	ExpandableListView expandableListView;

	private TextView yhzx_wytk_record_total;

	private PopupWindow m_popupWindow;

	private String getSelectItem="全部";

	private LinearLayout linLay_list,linlay;
	private Button btn_Buy;


	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.yhzx_accountdetail);
		initView();
		isFirstLanch = true;

		selectDate();
		selectType();
		timeRegion=1;
		change=true;
		startDetailThread();

		loadMoreButton.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				loadMoreButton.setText("正在加载中..."); // 设置按钮文字
				loadMoreButton.setEnabled(false);
				handler.postDelayed(new Runnable() {
					public void run() {
						pageNo += 1;
						change = false;
						startDetailThread();
						loadMoreButton.setText("点击加载更多"); // 恢复按钮文字
						loadMoreButton.setEnabled(true);
					}
				}, 2000);

			}
		});

		btn_Buy.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

				PreferencesUtils pUtil = new PreferencesUtils(AccountDetailActivity.this, Constants.PREFERENCES_NAME);
				Intent intent = new Intent();
				int ssq_size = pUtil.getInt("ssq_size", 0);
				if (ssq_size != 0) {
					ArrayList<BallDTO> list = new ArrayList<BallDTO>();
					for (int i = 0; i < ssq_size; i++) {
						BallDTO ball = new BallDTO();
						ball.setSsq_ball(pUtil.getString("ssq_ball" + i, ""));
						list.add(ball);
					}
					intent.putExtra("list_ssqdto", list);
					intent.putExtra("AllMoney", pUtil.getInt("ssq_allMoney", 0));
					intent.setClass(AccountDetailActivity.this, SsqxhlbActivity.class);
					Toast.makeText(AccountDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
							Toast.LENGTH_SHORT).show();
				} else {
					intent.setClass(AccountDetailActivity.this, SsqxhActivity.class);
				}
				startActivity(intent);
			}
		});
	}

	/*
	 * 根据类型筛选
	 * */
	public void selectType()
	{
        btn_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
				getSelectItem="全部";
                pageNo = 1;
                pageSize = 10;
                change = true;
                type = 0;
                adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
                if (isFirstLanch == false) {
                    startDetailThread();
                }
                isFirstLanch = false;

            }
        });

        btn_buyLottery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
				getSelectItem="购彩";
                pageNo = 1;
                pageSize = 10;
                change = true;
                type = 1;
                adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
                if (isFirstLanch == false) {
                    startDetailThread();
                }
                isFirstLanch = false;

            }
        });
        btn_recharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
				getSelectItem="充值";
                pageNo = 1;
                pageSize = 10;
                change = true;
                type = 2;
                adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
                if (isFirstLanch == false) {
                    startDetailThread();
                }
                isFirstLanch = false;
            }
        });
        btn_reward.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
				getSelectItem="派奖";
                pageNo = 1;
                pageSize = 10;
                change = true;
                type = 3;
                adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
                if (isFirstLanch == false) {
                    startDetailThread();
                }
                isFirstLanch = false;
            }
        });

        btn_drawings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
				getSelectItem="提款";
                pageNo = 1;
                pageSize = 10;
                change = true;
                type = 4;
                adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
                if (isFirstLanch == false) {
                    startDetailThread();
                }
                isFirstLanch = false;
            }
        });
	}
		/**selType.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(AccountDetailActivity.this);

				// 小目录框的设置
				View menuview = inflater.inflate(R.layout.public_acc_detail_all, null);
				m_popupWindow = new PopupWindow(menuview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

				m_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				m_popupWindow.setOutsideTouchable(true);
				m_popupWindow.showAtLocation(menuview, Gravity.RIGHT | Gravity.TOP, 40, 98);
				m_popupWindow.showAsDropDown(selDate);

				selType.setBackgroundDrawable(getResources().getDrawable(R.drawable.account_title_red));
				selType.setTextColor(getResources().getColor(R.color.ui_new_btn_bg));
				m_popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
					@Override
					public void onDismiss() {
						selType.setBackgroundDrawable(getResources().getDrawable(R.drawable.account_title_black));
						//ui_new_txt_content_normal
						selType.setTextColor(getResources().getColor(R.color.ui_new_txt_content_normal));
					}
				});

				menuview.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();

					}
				});

				Button btn_all = (Button) menuview.findViewById(R.id.btn_all);
				btn_all.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						m_popupWindow.dismiss();
						selType.setText("全部");
						getSelectItem="全部";

						pageNo = 1;
						pageSize = 10;
						change = true;
						type = 0;
						adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
						if (isFirstLanch == false) {
							startDetailThread();
						}
						isFirstLanch = false;

					}
				});

				Button btn_buyLottery = (Button) menuview.findViewById(R.id.btn_buyLottery);
				btn_buyLottery.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						m_popupWindow.dismiss();
						selType.setText("购彩");
						getSelectItem="购彩";

						pageNo = 1;
						pageSize = 10;
						change = true;
						type = 1;
						adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
						if (isFirstLanch == false) {
							startDetailThread();
						}
						isFirstLanch = false;

					}
				});
				Button btn_recharge = (Button) menuview.findViewById(R.id.btn_recharge);
				btn_recharge.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						selType.setText("充值");
						getSelectItem="充值";

						pageNo = 1;
						pageSize = 10;
						change = true;
						type = 2;
						adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
						if (isFirstLanch == false) {
							startDetailThread();
						}
						isFirstLanch = false;
					}
				});
				Button btn_reward = (Button) menuview.findViewById(R.id.btn_reward);
				btn_reward.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						selType.setText("派奖");
						getSelectItem="派奖";

						pageNo = 1;
						pageSize = 10;
						change = true;
						type = 3;
						adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
						if (isFirstLanch == false) {
							startDetailThread();
						}
						isFirstLanch = false;
					}
				});

				Button btn_drawings = (Button) menuview.findViewById(R.id.btn_drawings);
				btn_drawings.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						selType.setText("提款");
						getSelectItem="提款";

						pageNo = 1;
						pageSize = 10;
						change = true;
						type = 4;
						adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
						if (isFirstLanch == false) {
							startDetailThread();
						}
						isFirstLanch = false;
					}
				});
			}
		});
	}* */

	/*
	 * 根据时间段查询，当天，一周
	 * */
	public void selectDate()
	{

		selDate.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(AccountDetailActivity.this);

				// 小目录框的设置
				View menuview = inflater.inflate(R.layout.public_acc_detail, null);
				m_popupWindow = new PopupWindow(menuview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

				m_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				m_popupWindow.setOutsideTouchable(true);
				m_popupWindow.showAtLocation(menuview, Gravity.BOTTOM, 0, 0);
				m_popupWindow.showAsDropDown(selDate);

				selDate.setBackgroundDrawable(getResources().getDrawable(R.drawable.account_title_red));
				selDate.setTextColor(getResources().getColor(R.color.ui_new_btn_bg));
				m_popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
					@Override
					public void onDismiss() {
						selDate.setBackgroundDrawable(getResources().getDrawable(R.drawable.account_title_black));
						selDate.setTextColor(getResources().getColor(R.color.ui_new_txt_content_normal));
					}
				});


				menuview.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();

					}
				});

				Button btn_today = (Button) menuview.findViewById(R.id.btn_today);
				btn_today.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						//expandableListView.removeAllViews();

						m_popupWindow.dismiss();
						selDate.setText("当天");
						m_popupWindow.dismiss();
						timeRegion = 0;
						pageNo = 1;
						pageSize = 10;
						change = true;
						adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
						startDetailThread();
					}
				});

				Button btn_week = (Button) menuview.findViewById(R.id.btn_week);
				btn_week.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						showList();
						m_popupWindow.dismiss();
						selDate.setText("最近一周");
						m_popupWindow.dismiss();
						timeRegion = 1;
						pageNo = 1;
						pageSize = 10;
						change = true;
						adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
						startDetailThread();
					}
				});
				Button btn_month = (Button) menuview.findViewById(R.id.btn_month);
				btn_month.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						showList();
						m_popupWindow.dismiss();
						selDate.setText("最近一月");
						m_popupWindow.dismiss();
						timeRegion = 2;
						pageNo = 1;
						pageSize = 10;
						change = true;
						adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
						startDetailThread();
					}
				});
				Button btn_threeMonth = (Button) menuview.findViewById(R.id.btn_threeMonth);
				btn_threeMonth.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						//expandableListView.removeAllViews();
						m_popupWindow.dismiss();
						selDate.setText("最近三月");
						m_popupWindow.dismiss();
						timeRegion = 3;
						pageNo = 1;
						pageSize = 10;
						change = true;
						adapter = new PaginationAdapter(new ArrayList<Map<String, Object>>());
						startDetailThread();
					}
				});
			}
		});
	}


	public void onResume() {
		super.onResume();

	}

	public void onPause() {
		super.onPause();

	}

	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask

		String action;
		String UserID;

		// 1.准备运行
		protected void onPreExecute() {
			showdialog.showDialog(AccountDetailActivity.this);
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... paramsArr) {
			// 处理后台执行的任务，在后台线程执行
			String strResult = null;
			action = paramsArr[1];
			// 获取请求返回值
			String UserID = ApplicationData.getInstance().getUserID();
			strResult = GetRequestParams.getRequestUserIDResult(paramsArr[0], UserID, action, getApplicationContext());
			// 获取请求返回值
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						if (action.equals("110")) {
							rData = new ArrayList<Map<String, Object>>();
							rData = getData(result);
							showList();
							showdialog.closeDialog();
							if(rData !=null)
							{
								if(rData.size()>0)
								{
									linLay_list.setVisibility(View.VISIBLE);
									linlay.setVisibility(View.GONE);
								}else{
									linLay_list.setVisibility(View.GONE);
									linlay.setVisibility(View.VISIBLE);
								}
							}
						}
					} else {
						Toast.makeText(AccountDetailActivity.this, js.getString("Data"), Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				} finally {
					showdialog.closeDialog();
				}
			} else {
				Toast.makeText(AccountDetailActivity.this, getString(R.string.problem_01), Toast.LENGTH_LONG).show();
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}

	}

	private void initView() {
		linlay=(LinearLayout)findViewById(R.id.linLay);
		linLay_list=(LinearLayout)findViewById(R.id.linLay_list);
		btn_Buy=(Button)findViewById(R.id.btn_Buy);
		selDate = (TextView) findViewById(R.id.yhzx_accountdetail_seldate);
		//selType = (TextView) findViewById(R.id.yhzx_accountdetail_seltype);
		btn_all=(Button)findViewById(R.id.btn_all);
		btn_buyLottery=(Button)findViewById(R.id.btn_buyLottery);
		btn_recharge=(Button)findViewById(R.id.btn_recharge);
		btn_reward=(Button)findViewById(R.id.btn_reward);
		btn_drawings=(Button)findViewById(R.id.btn_drawings);

		loadMoreView = getLayoutInflater().inflate(R.layout.loadmore, null);
		loadMoreButton = (Button) loadMoreView.findViewById(R.id.loadMoreButton);
		expandableListView = (ExpandableListView) findViewById(R.id.account_expandableListview);
		// 标题
		titleBar();
		yhzx_wytk_record_total = (TextView) findViewById(R.id.yhzx_wytk_record_total);
	}

	/**
	 * 显示汇总
	 *
	 * @param js
	 */
	public void showTotal(JSONObject js) {
		// TODO Auto-generated method stub
		try {
			if (type == 0) {
				Map<String, Object> map = ConvertJsonToList.getMap(ConvertJsonToList.getMap(js.getString("Data"))
						.get("total").toString());
				yhzx_wytk_record_total.setText(Html.fromHtml("充值" + "<font color='#fe5052'>"
						+ String.valueOf(map.get("cz")) + "</font>" + "元，购彩" + "<font color='#fe5052'>"
						+ map.get("gc").toString() + "</font>" + "元，中奖" + "<font color='#fe5052'>"
						+ map.get("zj").toString() + "</font>" + "元，提款" + "<font color='#fe5052'>"
						+ map.get("tk").toString() + "</font>" + "元，佣金" + "<font color='#fe5052'>"
						+ map.get("yj").toString() + "</font>" + "元"));
			} else {
				// String Count =
				// String.valueOf(ConvertJsonToList.getMap(js.getString("Data")).get("Count"));
				String totalMoney = ConvertJsonToList.getMap(js.getString("Data")).get("totalMoney").toString();
				yhzx_wytk_record_total.setText(Html.fromHtml(getSelectItem
						+ "<font color='#fe5052'>" + totalMoney + "</font>" + "元"));
			}
		} catch (Exception e) {
			// e.printStackTrace();
			yhzx_wytk_record_total.setText("-");
		}
	}

	private void startDetailThread() {
		AsyncLoader task = new AsyncLoader();
		String[] dyn = new String[2];
		JSONObject paramArr = new JSONObject();
		try {
			// 设置请求所需参数
			paramArr.put("Type", type);
			paramArr.put("TimeRegion", timeRegion);
			paramArr.put("PageNo", pageNo);
			paramArr.put("PageSize", pageSize);
		} catch (JSONException ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}
		dyn[0] = paramArr.toString();
		dyn[1] = "110";// 104
		task.execute(dyn);
	}

	private List<Map<String, Object>> getData(String strResult) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			int code = Integer.parseInt(js.getString("Code"));
			if (code <= -1) {
				String msg = js.getString("Data");
				Toast.makeText(AccountDetailActivity.this, msg, Toast.LENGTH_LONG).show();
			} else {
				JSONTokener jsonParser1 = new JSONTokener(strResult);
				JSONObject js1 = (JSONObject) jsonParser1.nextValue();
				if (!"".equals(js1.getString("Data"))) {
					String Count = String.valueOf(ConvertJsonToList.getMap(js1.getString("Data")).get("Count"));
					intTotalNum = Integer.parseInt(Count);
					list = ConvertJsonToList.getList(String.valueOf(ConvertJsonToList.getMap(js1.getString("Data"))
							.get("item")));
				} else {
					// 数据为空时为0
					intTotalNum = 0;
				}
			}
		} catch (JSONException ex) {
			// 异常处理代码
			Log.e("error", ex.toString());
		}

		return list;
	}

	public void showList() {
		// 先删除FooterView
		expandableListView.removeFooterView(loadMoreView);
		int maxPage = (intTotalNum % pageSize == 0) ? (intTotalNum / pageSize) : (intTotalNum / pageSize + 1);
		if (pageNo < maxPage) {
			nextPage = true;
		} else {
			nextPage = false;
		}
		if (nextPage) {
			expandableListView.addFooterView(loadMoreView);
		} else {
			expandableListView.removeFooterView(loadMoreView);
		}
		if(rData !=null)
		{
		  if (rData.size() != 0) {
			for (int i = 0; i < rData.size(); i++) {
				adapter.addItem(rData.get(i));
			}
		  }
		}

		if (change) {
			adapter.notifyDataSetChanged();
			expandableListView.setAdapter(adapter);
		} else {
			adapter.notifyDataSetChanged();
		}
		for (int i = 0; i < adapter.getGroupCount(); i++) {
			expandableListView.expandGroup(i);
		}
		change = false;
	}

	class PaginationAdapter extends BaseExpandableListAdapter {

		List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
		Map<String, Object> date = new HashMap<String, Object>();

		public PaginationAdapter(List<Map<String, Object>> accountList) {
			this.data = accountList;
		}

		public void addItem(Map<String, Object> map) {
			String date = getDateByString(map.get("Time").toString());
			boolean isFound = false;
			for (Map<String, Object> itemMap : data) {
				if (TextUtils.equals(itemMap.get("date").toString(), date)) {
					((List<Map<String, Object>>) itemMap.get("content")).add(map);
					isFound = true;
					break;
				}
			}
			if (isFound == false) {
				Map<String, Object> tempItem = new HashMap<String, Object>();
				List<Map<String, Object>> dataitem = new ArrayList<Map<String, Object>>();
				dataitem.add(map);
				tempItem.put("date", date);
				tempItem.put("content", dataitem);
				data.add(tempItem);
			}
		}

		@Override
		public Object getChild(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getChildId(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return childPosition;
		}

		@Override
		public View getChildView(int groupPosition, int position, boolean isLastChild, View view, ViewGroup parent) {
			// TODO Auto-generated method stub
			if (view == null) {
				view = getLayoutInflater().inflate(R.layout.yhzx_accountdetail_list, null);
			}
			List<Map<String, Object>> accountList = (List<Map<String, Object>>) data.get(groupPosition).get("content");
			TextView tvDate = (TextView) view.findViewById(R.id.accountdetail_list_date);
			tvDate.setText(getTimeByString(accountList.get(position).get("Time").toString()));
			TextView tvType = (TextView) view.findViewById(R.id.accountdetail_list_type);
			TextView tvMoney = (TextView) view.findViewById(R.id.accountdetail_list_balance);
			TextView tvTypeTitle = (TextView) view.findViewById(R.id.accountdetail_list_type_title);
			TextView tvMoneyType = (TextView) view.findViewById(R.id.accountdetail_list_balance_type);
			TextView tvallMoney = (TextView) view.findViewById(R.id.accountdetail_list_allmoney);
			TextView tvallMoneyTitle = (TextView) view.findViewById(R.id.accountdetail_list_allmoney_title);
			TextView accountdetail_list_zt_title = (TextView) view.findViewById(R.id.accountdetail_list_zt_title);
			TextView accountdetail_list_zt = (TextView) view.findViewById(R.id.accountdetail_list_zt);

			double balance = 0;
			try {
				balance = Double.parseDouble(accountList.get(position).get("Balance").toString().replace(",",""));
				tvallMoney.setText(String.format("%1$.2f元", balance));
			} catch (Exception e) {
				tvallMoney.setText("-");

			}

			if (type == 0) {
				tvallMoneyTitle.setVisibility(View.VISIBLE);
				tvallMoney.setVisibility(View.VISIBLE);
				accountdetail_list_zt_title.setVisibility(View.GONE);
				accountdetail_list_zt.setVisibility(View.GONE);

				try {
					if (accountList.get(position).get("Name") != null) {// Type
						tvType.setText(accountList.get(position).get("Name").toString());
					}
				} catch (Exception e) {
					tvType.setText("");
				}
			} else {
				tvType.setText(getSelectItem);
				if (!"".equals(getSelectItem)&&accountList.get(position).get("Name") != null){
					tvType.setText(accountList.get(position).get("Name").toString());
				}
				try {
					if (accountList.get(position).get("Name") != null) {// Type
						accountdetail_list_zt.setText(accountList.get(position).get("Name").toString());
					}
				} catch (Exception e) {
					accountdetail_list_zt.setText("");
				}
				accountdetail_list_zt_title.setVisibility(View.VISIBLE);
				accountdetail_list_zt.setVisibility(View.VISIBLE);
				tvallMoneyTitle.setVisibility(View.GONE);
				tvallMoney.setVisibility(View.GONE);
				if (type == 3) {
					accountdetail_list_zt_title.setVisibility(View.INVISIBLE);
					accountdetail_list_zt.setVisibility(View.INVISIBLE);
				}
			}
			String money = accountList.get(position).get("Money").toString().trim();
			if(type==0){
				int moneyType = Integer.parseInt(accountList.get(position).get("Type").toString().trim());
				if(moneyType == 1){
					tvMoney.setText("+"+money.replace("-", "").replace("+", "") + "（￥）");
					tvMoney.setTextColor(0xfff56367);
				}else{
					tvMoney.setText("-"+money.replace("-", "").replace("+", "") + "（￥）");
					tvMoney.setTextColor(0xff3bb5f4);
				}
			}else if(type==1||type==4){
				tvMoney.setText("-"+money.replace("-", "").replace("+", "") + "（￥）");
				tvMoney.setTextColor(0xff3bb5f4);
			}else {
				tvMoney.setText("+"+money.replace("-", "").replace("+", "") + "（￥）");
			}
//			if(type == 0){
//				if (money.contains("-")) {
//					tvMoneyType.setText("支出：");
//				} else {
//					tvMoneyType.setText("收入：");
//				}
//				moneyType=1的是收入 其他的为支出
//				int moneyType = Integer.parseInt(accountList.get(position).get("Type").toString().trim());
//				if(moneyType == 1){
//					tvMoneyType.setText("收入：");
//				}else{
//					tvMoneyType.setText("支出：");
//				}
//			}else{
//				tvMoneyType.setText("金额：");}
			return view;
		}

		@Override
		public int getChildrenCount(int groupPosition) {
			// TODO Auto-generated method stub
			List<Map<String, Object>> dataitem = (List<Map<String, Object>>) data.get(groupPosition).get("content");
			if (dataitem.isEmpty()) {
				return 0;
			}
			return dataitem.size();
		}

		@Override
		public Object getGroup(int groupPosition) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public int getGroupCount() {
			// TODO Auto-generated method stub
			return data.size();
		}

		@Override
		public long getGroupId(int groupPosition) {
			// TODO Auto-generated method stub
			return groupPosition;
		}

		@Override
		public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			GroupExpandableListHolder holder = null;
			if (convertView == null) {
				convertView = getLayoutInflater().inflate(R.layout.item_group, null);
				holder = new GroupExpandableListHolder();
				holder.title = (TextView) convertView.findViewById(R.id.item_group_title);
				holder.indicator = (ImageView) convertView.findViewById(R.id.item_group_status);
				convertView.setTag(holder);
			} else {
				holder = (GroupExpandableListHolder) convertView.getTag();
			}

			holder.title.setText(data.get(groupPosition).get("date").toString());
			holder.indicator.setVisibility(View.GONE);
			return convertView;
		}

		@Override
		public boolean hasStableIds() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean isChildSelectable(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return false;
		}

		private class GroupExpandableListHolder {
			TextView title;
			ImageView indicator;
		}
	}

	// titleBar标题栏
	public void titleBar() {
		TextView back = (TextView) findViewById(R.id.top_title_back);
		// back.setText("<<<<<<--");
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});
		TextView info = (TextView) findViewById(R.id.top_title_info);
		info.setText(R.string.yhzx_zjgl_zhmx);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			this.finish();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}

	};

	public static String getDateTime(String b) {
		java.util.Date d = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = sdf.parse(b);
		} catch (ParseException pe) {
			// pe.printStackTrace();
		}
		SimpleDateFormat sdf1 = new SimpleDateFormat("MM-dd HH:mm:ss");
		return sdf1.format(d);
	}

	public static String getDateByString(String b) {
		b = b.trim();
		java.util.Date d = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = sdf.parse(b);
		} catch (ParseException pe) {
		}
		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
		return sdf1.format(d);
	}

	public static String getTimeByString(String b) {
		b = b.trim();
		java.util.Date d = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = sdf.parse(b);
		} catch (ParseException pe) {
		}
		SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm:ss");
		return sdf1.format(d);
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
	};
}